package com.errol.batchprocessor.batchprocessor.advisor;

import com.renjia.entity.AbstractImportBatch;
import com.renjia.service.generic.middleware.batchprocessor.abs.AbstractAdvisor;
import com.renjia.service.generic.middleware.batchprocessor.payload.AbstractBatchPayload;
import com.renjia.service.generic.middleware.batchprocessor.payload.AbstractPiecePayload;
import com.renjia.service.generic.middleware.batchprocessor.payload.AbstractSinglePayload;
import org.springframework.lang.NonNull;

/**
 * 分片开始执行的扩展点
 *
 * @author zhang xiao bin
 * @version v1.0
 * @date 2021/02/23
 * @since v5.0.5
 **/
public interface PieceStartAdvisor<IE extends AbstractImportBatch, AT extends Enum<?>, BE, SE, BP extends AbstractBatchPayload<IE, AT, BE, SE>, PP extends AbstractPiecePayload<SE, SP>, SP extends AbstractSinglePayload<SE>>
        extends AbstractAdvisor<AbstractBatchPayload<IE, AT, BE, SE>> {

    /**
     * 分片启动时的扩展点，准备数据
     *
     * @param piecePayload 分片数据
     * @param batchPayload 批次数据
     * @return true 表示分片启动成功，false 表示拦截分片；该扩展点的所有实现只要有一个返回 false，即拦截该分片
     */
    boolean doPrepareOnPieceStart(@NonNull PP piecePayload, @NonNull BP batchPayload);
}
